from PyQt6.QtWidgets import (
    QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton,
    QGroupBox, QSpinBox, QComboBox, QTableWidget, QTableWidgetItem, 
    QHeaderView
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QColor

class ResumeWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
    
    def init_ui(self):
        """初始化简历库管理界面"""
        self.setStyleSheet("""
            QWidget {
                background-color: white;
                color: black;
                font-family: 'Microsoft YaHei', Arial, sans-serif;
            }
            QGroupBox {
                font-weight: bold;
                color: black;
                background-color: white;
                border: 1px solid #ccc;
                border-radius: 6px;
                margin-top: 8px;
                padding-top: 8px;
            }
            QGroupBox::title {
                subcontrol-origin: margin;
                left: 10px;
                padding: 0 5px 0 5px;
                color: black;
            }
        """)
        
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(15, 15, 15, 15)
        main_layout.setSpacing(10)
        
        # 标题和保存按钮
        header_layout = QHBoxLayout()
        
        title_label = QLabel("📁 简历库管理")
        title_label.setStyleSheet("""
            QLabel {
                font-size: 20px;
                font-weight: bold;
                color: black;
                background-color: white;
                border: none;
            }
        """)
        header_layout.addWidget(title_label)
        header_layout.addStretch()
        

        
        main_layout.addLayout(header_layout)
        
        # 创建搜索筛选分组
        self.create_search_filter(main_layout)
        
        # 创建简历列表分组
        self.create_resume_list(main_layout)
    
    def create_search_filter(self, layout):
        """创建搜索筛选分组"""
        # 搜索筛选分组
        search_group = QGroupBox("🔍 搜索筛选")
        search_layout = QHBoxLayout(search_group)
        search_layout.setSpacing(10)
        
        # 起始时间
        search_layout.addWidget(QLabel("起始时间:"))
        start_date = QLineEdit("2025-01-01")
        start_date.setFixedWidth(100)
        start_date.setStyleSheet("""
            QLineEdit {
                background-color: white;
                color: black;
                border: 1px solid #ccc;
                padding: 4px;
                border-radius: 3px;
            }
        """)
        search_layout.addWidget(start_date)
        
        # 结束时间
        search_layout.addWidget(QLabel("结束时间:"))
        end_date = QLineEdit("2025-12-31")
        end_date.setFixedWidth(100)
        end_date.setStyleSheet("""
            QLineEdit {
                background-color: white;
                color: black;
                border: 1px solid #ccc;
                padding: 4px;
                border-radius: 3px;
            }
        """)
        search_layout.addWidget(end_date)
        
        # 姓名搜索
        search_layout.addWidget(QLabel("姓名:"))
        name_input = QLineEdit()
        name_input.setPlaceholderText("输入姓名")
        name_input.setFixedWidth(120)
        name_input.setStyleSheet("""
            QLineEdit {
                background-color: white;
                color: black;
                border: 1px solid #ccc;
                padding: 4px;
                border-radius: 3px;
            }
        """)
        search_layout.addWidget(name_input)
        
        # 查询按钮
        search_btn = QPushButton("查询")
        search_btn.setStyleSheet("""
            QPushButton {
                background-color: #007bff;
                color: white;
                border: none;
                padding: 6px 20px;
                border-radius: 4px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: #0056b3;
            }
        """)
        search_layout.addWidget(search_btn)
        search_layout.addStretch()
        
        layout.addWidget(search_group)
       
    
    def create_resume_list(self, layout):
        """创建简历列表分组"""
        # 简历列表分组
        list_group = QGroupBox("📋 简历列表")
        list_layout = QVBoxLayout(list_group)
        
        # 简历表格
        table = QTableWidget()
        table.setColumnCount(8)
        table.setHorizontalHeaderLabels([
            "姓名", "年龄", "学历", "经验", "期望薪资", "工作地点", "状态", "操作"
        ])
        
        # 设置表格样式
        table.setStyleSheet("""
            QTableWidget {
                border: 1px solid #ccc;
                border-radius: 4px;
                background-color: white;
                gridline-color: #e0e0e0;
                selection-background-color: #e8f4fd;
            }
            QTableWidget::item {
                padding: 8px;
                border-bottom: 1px solid #e0e0e0;
            }
            QHeaderView::section {
                background-color: #f8f9fa;
                color: black;
                padding: 10px;
                border: none;
                font-weight: bold;
                border-bottom: 2px solid #dee2e6;
            }
        """)
        
        # 设置列宽
        header = table.horizontalHeader()
        header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)  # 姓名
        header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)  # 年龄
        header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)  # 学历
        header.setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)  # 经验
        header.setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents)  # 薪资
        header.setSectionResizeMode(5, QHeaderView.ResizeMode.Stretch)           # 地点
        header.setSectionResizeMode(6, QHeaderView.ResizeMode.ResizeToContents)  # 状态
        header.setSectionResizeMode(7, QHeaderView.ResizeMode.ResizeToContents)  # 操作
        
        # 添加示例数据
        sample_data = [
            ["张三", "28", "本科", "3-5年", "15K-20K", "深圳", "待联系"],
            ["李四", "25", "硕士", "1-3年", "12K-18K", "上海", "已联系"],
            ["王五", "30", "本科", "5-10年", "20K-30K", "北京", "面试中"],
            ["赵六", "26", "大专", "3-5年", "10K-15K", "广州", "已拒绝"],
            ["钱七", "32", "硕士", "5-10年", "25K-35K", "杭州", "待联系"]
        ]
        
        table.setRowCount(len(sample_data))
        for row, data in enumerate(sample_data):
            for col, value in enumerate(data):
                item = QTableWidgetItem(str(value))
                # 根据状态设置不同颜色
                if col == 6:  # 状态列
                    if value == "待联系":
                        item.setBackground(QColor("#fff3cd"))  # 浅黄色
                    elif value == "已联系":
                        item.setBackground(QColor("#d1ecf1"))  # 浅蓝色
                    elif value == "面试中":
                        item.setBackground(QColor("#d4edda"))  # 浅绿色
                    elif value == "已拒绝":
                        item.setBackground(QColor("#f8d7da"))  # 浅红色
                table.setItem(row, col, item)
            
            # 添加操作按钮
            action_widget = QWidget()
            action_layout = QHBoxLayout(action_widget)
            action_layout.setContentsMargins(5, 5, 5, 5)
            action_layout.setSpacing(5)
            
            view_btn = QPushButton("查看")
            view_btn.setStyleSheet("""
                QPushButton {
                    background-color: #007bff;
                    color: white;
                    border: none;
                    padding: 4px 8px;
                    border-radius: 3px;
                    font-size: 12px;
                }
                QPushButton:hover {
                    background-color: #0056b3;
                }
            """)
            action_layout.addWidget(view_btn)
            
            contact_btn = QPushButton("联系")
            contact_btn.setStyleSheet("""
                QPushButton {
                    background-color: #28a745;
                    color: white;
                    border: none;
                    padding: 4px 8px;
                    border-radius: 3px;
                    font-size: 12px;
                }
                QPushButton:hover {
                    background-color: #218838;
                }
            """)
            action_layout.addWidget(contact_btn)
            
            table.setCellWidget(row, 7, action_widget)
        
        list_layout.addWidget(table)
        layout.addWidget(list_group)
